package com.example.cpoopc.listview_test;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.animation.DecelerateInterpolator;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Scroller;

public class ScrollableLinearLayout extends LinearLayout
{
  private int position;
  private bl interf;
  private int mScaledTouchSlop;
  private int mPointerId0;
  private float mDownX;
  private float mDownY;
  private float mX1;
  private float mLastMotionY;
  private boolean i;
  private boolean j;
  private boolean k;
  private VelocityTracker vTracker;
  // 减速scroll,控制head
  private Scroller scrollA;
  // 辅助
  private Scroller scrollB;
  private long mTsO;
  private int p;
  private long q;
  // 控制listview
  private Scroller scroller;
  private int mDistance;
  private int mDuration;
  private int fy;
  private int mDuration2;
  private int mMinFlingV;
  private int mMaxFlingV;

  public ScrollableLinearLayout(Context paramContext)
  {
    super(paramContext);
    init(paramContext);
  }

  public ScrollableLinearLayout(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
    init(paramContext);
  }

  @SuppressLint({"NewApi"})
  private void init(Context context)
  {
    ViewConfiguration localViewConfiguration = ViewConfiguration.get(context);
    this.mScaledTouchSlop = localViewConfiguration.getScaledTouchSlop();
    this.mMinFlingV = localViewConfiguration.getScaledMinimumFlingVelocity();
    this.mMaxFlingV = localViewConfiguration.getScaledMaximumFlingVelocity();
    this.scrollA = new Scroller(context, new DecelerateInterpolator());
    this.scrollB = new Scroller(context);
    this.scroller = new Scroller(context);
    if (Build.VERSION.SDK_INT >= 11)
      setMotionEventSplittingEnabled(false);
  }

  public int getA()
  {
    return this.position;
  }

  public void setA(int paramInt)
  {
    this.position = paramInt;
  }

  public void setLvInterf(bl parambl)
  {
    this.interf = parambl;
  }

  public void computeScroll()
  {
    boolean bool1 = true;
    if (this.interf == null)
      return;
    if (this.scroller.computeScrollOffset())
      if (!this.interf.a())
      {
        this.mDuration = ((int)(this.mDuration - (System.currentTimeMillis() - this.mTsO)));
        if (this.mDuration < 0)
          this.mDuration = 0;
        this.mDistance -= this.scroller.getCurrY();
        if (this.mDistance < 0)
          this.mDistance = 0;
        this.scroller.forceFinished(bool1);
        ListView localListView = this.interf.getListView();
        if (localListView != null)
          localListView.smoothScrollBy(this.mDistance, this.mDuration);
      }
    for (boolean bool2 = bool1; ; bool2 = false)
    {
      if (this.scrollA.computeScrollOffset())
      {
        int y2 = this.scrollA.getCurrY();
        // 整体移动
        scrollTo(0, y2);
        this.interf.a(y2);
        bool2 = bool1;
      }
      int i1;
      if (this.scrollB.computeScrollOffset())
        if (this.interf.b())
        {
          this.mDuration2 = ((int)(this.mDuration2 - (System.currentTimeMillis() - this.q)));
          if (this.mDuration2 < 0)
            this.mDuration2 = 0;
          this.fy -= this.scrollB.getCurrY();
          if (this.fy < 0)
            this.fy = 0;
          i1 = getScrollY();
          this.scrollB.forceFinished(bool1);
          if (this.fy >= i1)
            break label349;
          this.scrollA.startScroll(0, i1, 0, -this.fy, this.mDuration2);
        }
      while (true)
      {
        if (!bool1)
          break label393;
        postInvalidate();
        return;
        int y3 = this.scroller.getCurrY() + this.p;
        if (y3 > this.position)
          y3 = this.position;
        scrollTo(0, y3);
        this.interf.a(y3);
        break;
        label349: if (this.fy != 0)
        {
          this.mDuration2 = (i1 * this.mDuration2 / this.fy);
          this.scrollA.startScroll(0, i1, 0, -i1, this.mDuration2);
          continue;
          bool1 = bool2;
        }
      }
      label393: break;
    }
  }

  public boolean dispatchTouchEvent(MotionEvent paramMotionEvent)
  {
    int i1 = 1;
//	  boolean i1 = true;
    if (this.interf == null)
      return super.dispatchTouchEvent(paramMotionEvent);
    if (this.vTracker == null)
      this.vTracker = VelocityTracker.obtain();
    this.vTracker.addMovement(paramMotionEvent);
    label309: label378: VelocityTracker localVelocityTracker;
    switch (0xFF & paramMotionEvent.getAction())
    {
    case MotionEvent.ACTION_OUTSIDE:
    case MotionEvent.ACTION_POINTER_DOWN:
    default:
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_MOVE:
      float currentY;
      do
      {
        do
        {
          int i11;
          do
          {
            while (true)
            {
            	// default
              return super.dispatchTouchEvent(paramMotionEvent);
              // action_down
              float cY = paramMotionEvent.getY();
              float cX = paramMotionEvent.getX();
              this.mLastMotionY = cY;
              this.mX1 = cX;
              this.mDownX = cX;
              this.mDownY = cY;
              this.mPointerId0 = paramMotionEvent.getPointerId(0);
              this.scrollA.forceFinished(i1);
              this.scrollB.forceFinished(i1);
              this.scroller.forceFinished(i1);
              this.mDistance = 0;
              this.mDuration = 0;
              this.p = 0;
              this.mTsO = 0L;
              this.fy = 0;
              this.mDuration2 = 0;
              this.q = 0L;
            }
            i11 = this.mPointerId0;
          }
          while (i11 == -1);// 移动
          int pointIndex = paramMotionEvent.findPointerIndex(i11);
          currentY = paramMotionEvent.getY(pointIndex);
          float currentX = paramMotionEvent.getX(pointIndex);
          int shiftY = (int)Math.abs(currentY - this.mDownY);
          int shiftX = (int)Math.abs(currentX - this.mDownX);
          int deltaY = (int)(currentY - this.mLastMotionY);
          if ((!this.i) && (shiftY > this.mScaledTouchSlop) && (shiftX < shiftY))
            this.i = i1;
          if (deltaY >= 0)
            break;
          int i16 = i1;
          this.k = i16;
        }
        while (!this.i);
        if (this.j)
          break label456;
        if (((this.k) && (this.interf.a())) || ((!this.k) && (this.interf.b())))
        {
          this.j = i1;
          this.mLastMotionY = currentY;
        }
      }
      while (!this.j);
      int deltaY2 = (int)(currentY - this.mLastMotionY);
      this.mLastMotionY = currentY;
      int toY = getScrollY() - deltaY2;
      if (toY > this.position)
        toY = this.position;
      while (true)
      {
        scrollTo(0, toY);
        invalidate();
        this.interf.a(toY);
        break;
        int i17 = 0;
        break label309;
        if (((!this.k) || (this.interf.a())) && ((this.k) || (this.interf.b())))
          break label378;
        this.j = false;
        this.mLastMotionY = currentY;
        break label378;
        if (toY < 0)
          toY = 0;
      }
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
      label456: if (this.vTracker != null)
      {
        localVelocityTracker = this.vTracker;
        localVelocityTracker.computeCurrentVelocity(1000, this.mMaxFlingV);
      }
      break;
    case MotionEvent.ACTION_POINTER_UP:
    }
    for (int i4 = (int)localVelocityTracker.getYVelocity(this.mPointerId0); ; i4 = 0)
    {
      this.mPointerId0 = -1;
      if (this.vTracker != null)
      {
        this.vTracker.recycle();
        this.vTracker = null;
      }
      if (this.i)
        if (Math.abs(i4) > this.mMinFlingV)
        {
          int i6 = -i4;
          int i7 = this.position - getScrollY();
          if ((i6 > 0) && (i7 > 0))
          {
            this.scrollB.forceFinished(i1);
            this.scrollA.forceFinished(i1);
            this.scroller.fling(0, 0, 0, i6, 0, 2147483647, 0, 2147483647);
            this.mDuration = this.scroller.getDuration();
            this.mDistance = this.scroller.getFinalY();
            this.mTsO = System.currentTimeMillis();
            this.p = getScrollY();
            invalidate();
            this.i = false;
            this.j = false;
            int i10 = paramMotionEvent.getAction();
            paramMotionEvent.setAction(3);
            boolean bool4 = super.dispatchTouchEvent(paramMotionEvent);
            paramMotionEvent.setAction(i10);
            return bool4;
          }
          if (i6 < 0)
          {
            this.scroller.forceFinished(i1);
            this.scrollB.fling(0, 0, 0, -i6, 0, 2147483647, 0, 2147483647);
            this.mDuration2 = this.scrollB.getDuration();
            this.fy = this.scrollB.getFinalY();
            this.q = System.currentTimeMillis();
            invalidate();
            this.i = false;
            if (this.j)
            {
              this.j = false;
              int i9 = paramMotionEvent.getAction();
              paramMotionEvent.setAction(3);
              boolean bool3 = super.dispatchTouchEvent(paramMotionEvent);
              paramMotionEvent.setAction(i9);
              return bool3;
            }
          }
          else if (this.i)
          {
            this.i = false;
            if (this.j)
            {
              this.j = false;
              int i8 = paramMotionEvent.getAction();
              paramMotionEvent.setAction(3);
              boolean bool2 = super.dispatchTouchEvent(paramMotionEvent);
              paramMotionEvent.setAction(i8);
              return bool2;
            }
          }
        }
        else
        {
          this.i = false;
          if (this.j)
          {
            this.j = false;
            int actionCurrent = paramMotionEvent.getAction();
            paramMotionEvent.setAction(MotionEvent.ACTION_CANCEL);
            boolean bool1 = super.dispatchTouchEvent(paramMotionEvent);
            paramMotionEvent.setAction(actionCurrent);
            return bool1;
          }
        }
      this.i = false;
      this.j = false;
      break;
      int i3 = (0xFF00 & paramMotionEvent.getAction()) >> 8;
      if (paramMotionEvent.getPointerId(i3) != this.mPointerId0)
        break;
      if (i3 == 0);
      while (true)
      {
        this.mLastMotionY = paramMotionEvent.getY(i1);
        this.mX1 = paramMotionEvent.getX(i1);
        this.mPointerId0 = paramMotionEvent.getPointerId(i1);
        if (this.vTracker == null)
          break;
        this.vTracker.clear();
        break;
        int i2 = 0;
      }
    }
  }

  protected void onMeasure(int paramInt1, int paramInt2)
  {
    super.onMeasure(paramInt1, View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.getSize(paramInt2) + this.position, 1073741824));
  }

  public void requestDisallowInterceptTouchEvent(boolean paramBoolean)
  {
    super.requestDisallowInterceptTouchEvent(paramBoolean);
  }
}